package com.demo.modules.mq.controller;

import com.demo.common.core.result.R;
import com.demo.modules.mq.rabbit.RabbitAnnouncementMessage;
import com.demo.modules.mq.rabbit.service.RabbitMessageProducerService;
import com.demo.modules.mq.rabbit.service.dead.RabbitDeadMessageProducerService;
import com.demo.modules.mq.rabbit.service.direct.RabbitDirectMessageProducerService;
import com.demo.modules.mq.rabbit.service.fanout.RabbitFanoutMessageConsumerService;
import com.demo.modules.mq.rabbit.service.fanout.RabbitFanoutMessageProducerService;
import com.demo.modules.mq.rabbit.service.header.RabbitHeaderMessageProducerService;
import com.demo.modules.mq.rabbit.service.topic.RabbitTopicMessageProducerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author MyPC
 */
@Api(tags = "RabbitMQ接口")
@RequestMapping("/mq-rabbit")
@RestController
public class RabbitMqController {

    @Autowired
    private RabbitMessageProducerService rabbitMessageProducerService;

    @Autowired
    private RabbitFanoutMessageProducerService rabbitFanoutMessageProducerService;

    @Autowired
    private RabbitDirectMessageProducerService rabbitDirectMessageProducerService;

    @Autowired
    private RabbitTopicMessageProducerService rabbitTopicMessageProducerService;

    @Autowired
    private RabbitHeaderMessageProducerService rabbitHeaderMessageProducerService;

    @Autowired
    private RabbitDeadMessageProducerService rabbitDeadMessageProducerService;

    @ApiOperation("发送消息")
    @PostMapping("pushMessage")
    public R<Boolean> pushMessage(String content) {
        RabbitAnnouncementMessage rabbitAnnouncementMessage = new RabbitAnnouncementMessage();
        rabbitAnnouncementMessage.setId("1");
        rabbitAnnouncementMessage.setContent(content);
        rabbitMessageProducerService.contextLoads(rabbitAnnouncementMessage);
        return R.ok();
    }

    @ApiOperation("带回调回调发送消息")
    @PostMapping("returnMessage")
    public R<Boolean> returnMessage() throws InterruptedException {
        rabbitMessageProducerService.returnMessage();
        return R.ok();
    }

    @ApiOperation("work发送消息")
    @PostMapping("work-pushMessage")
    public R<Boolean> workPushMessage() throws InterruptedException {
        rabbitMessageProducerService.workQueue1();
        return R.ok();
    }

    @ApiOperation("fanout交换机发送消息")
    @PostMapping("fanout-pushMessage")
    public R<Boolean> fanOutPushMessage() {
        rabbitFanoutMessageProducerService.fanoutQueue();
        return R.ok();
    }

    @ApiOperation("direct交换机发送消息")
    @PostMapping("direct-pushMessage")
    public R<Boolean> directPushMessage() {
        rabbitDirectMessageProducerService.directQueue();
        return R.ok();
    }

    @ApiOperation("topic交换机发送消息")
    @PostMapping("topic-pushMessage")
    public R<Boolean> topicPushMessage(String routKet) {
        rabbitTopicMessageProducerService.topicQueue(routKet);
        return R.ok();
    }

    @ApiOperation("header交换机发送消息")
    @PostMapping("header-pushMessage")
    public R<Boolean> headerPushMessage() {
        rabbitHeaderMessageProducerService.headerQueue();
        return R.ok();
    }


    @ApiOperation("死信队列测试")
    @PostMapping("dead-pushMessage")
    public R<Boolean> deadPushMessage() {
        rabbitDeadMessageProducerService.sendMessage();
        return R.ok();
    }
}
